package ${serviceImplPackage};

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ${daoPackage}.${pojo.getDeclarationName()}DAO;
import ${clazz.entityName};
import ${servicePackage}.${pojo.getDeclarationName()}Service;

public class ${pojo.getDeclarationName()}ServiceImpl implements ${pojo.getDeclarationName()}Service {
	private static final Log log = LogFactory.getLog(${pojo.getDeclarationName()}Service.class);
	
	private ${pojo.getDeclarationName()}DAO ${pojo.getDeclarationName()?uncap_first}DAO = null;
	public ${pojo.getDeclarationName()}DAO get${pojo.getDeclarationName()}DAO() {
		return ${pojo.getDeclarationName()?uncap_first}DAO;
	}
	public void set${pojo.getDeclarationName()}DAO(${pojo.getDeclarationName()}DAO ${pojo.getDeclarationName()?uncap_first}DAO) {
		this.${pojo.getDeclarationName()?uncap_first}DAO = ${pojo.getDeclarationName()?uncap_first}DAO;
	}

	public boolean create(${pojo.getDeclarationName()} transientInstance) {
		log.debug("creating ${pojo.getDeclarationName()} instance");
		try {
			${pojo.getDeclarationName()?uncap_first}DAO.save(transientInstance);
			log.debug("create successful");
			return true;
		} catch (RuntimeException re) {
			log.error("create failed", re);
		}
		return false;
	}

	public boolean delete(Long id) {
		log.debug("deleting ${pojo.getDeclarationName()} instance");
		try {
			${pojo.getDeclarationName()} persistentInstance = ${pojo.getDeclarationName()?uncap_first}DAO.findById(id);
			${pojo.getDeclarationName()?uncap_first}DAO.delete(persistentInstance);
			log.debug("delete successful");
			return true;
		} catch (RuntimeException re) {
			log.error("delete failed", re);
		}
		return false;
	}

	public List retrieve() {
		log.debug("retrieving ${pojo.getDeclarationName()} instances");
		try {
			List list = ${pojo.getDeclarationName()?uncap_first}DAO.findAll();
			log.debug("retrieve successful");
			return list;
		} catch (RuntimeException re) {
			log.error("retrieve instances failed", re);
		}
		return null;
	}

	public ${pojo.getDeclarationName()} retrieve(Long id) {
		log.debug("retrieving ${pojo.getDeclarationName()} instance");
		try {
			${pojo.getDeclarationName()} ${pojo.getDeclarationName()?uncap_first} = ${pojo.getDeclarationName()?uncap_first}DAO.findById(id);
			log.debug("retrieve successful");
			return ${pojo.getDeclarationName()?uncap_first};
		} catch (RuntimeException re) {
			log.error("retrieve instance failed", re);
		}
		return null;
	}

	public boolean update(${pojo.getDeclarationName()} instance) {
		log.debug("updating ${pojo.getDeclarationName()} instance");
		try {
			${pojo.getDeclarationName()?uncap_first}DAO.attachDirty(instance);
			log.debug("update successful");
			return true;
		} catch (RuntimeException re) {
			log.error("update failed", re);
		}
		return false;
	}

}
